package ar.com.ford.it.fullEconomics.facade;

import java.util.Collection;
import ar.com.ford.it.fullEconomics.exception.FullEconomicsException;
import ar.com.ford.it.fullEconomics.logic.AgreementItemLogic;
import ar.com.ford.it.fullEconomics.logic.AgreementLogic;
import ar.com.ford.it.fullEconomics.persistence.dto.Teesr03Agreement;
import ar.com.ford.it.fullEconomics.persistence.dto.Teesr04Agreemitem;
import ar.com.ford.it.fullEconomics.persistence.dto.Teess01Supplier;
import ar.com.ford.it.fullEconomics.struct.AgreementFindStruct;
import ar.com.ford.it.fullEconomics.wslx.FullEconomicsWslxUser;

public class AgreementFacade {

    /**
     * Crea el agreement
     * 
     * @param agreement
     * @param user
     * @return
     * @throws FullEconomicsException
     */
    public Teesr03Agreement createAgreement(Teesr03Agreement agreement,
                                            FullEconomicsWslxUser user)
            throws FullEconomicsException {
        AgreementLogic logic = new AgreementLogic();
        Teesr03Agreement req = logic.createAgreement(agreement, user);
        return req;
    }

    /**
     * guarda cambios hechos en el agreement
     * 
     * @param agreement
     * @param user
     * @throws FullEconomicsException
     */
    public void updateAgreement(Teesr03Agreement agreement,
                                FullEconomicsWslxUser user)
            throws FullEconomicsException {
        AgreementLogic logic = new AgreementLogic();
        logic.updateAgreement(agreement, user);
    }

    /**
     * Borra el agreement pasado por parametro y sus items
     * 
     * @param agreement
     * @throws FullEconomicsException
     */
    public void deleteAgreement(Teesr03Agreement agreement)
            throws FullEconomicsException {
        AgreementLogic logic = new AgreementLogic();
        logic.deleteAgreement(agreement);
    }

    /**
     * busqueda de agreement
     * 
     * @param findStruct
     * @return
     * @throws FullEconomicsException
     */
    public Collection<Teesr03Agreement> findAgreements(
                                                       AgreementFindStruct findStruct)
            throws FullEconomicsException {
        AgreementLogic logic = new AgreementLogic();
        Collection<Teesr03Agreement> ret = logic.findAgreements(findStruct);
        return ret;
    }
    
    /**
     * busqueda de historico de agreement items
     * 
     * @param findStruct
     * @return
     * @throws FullEconomicsException
     */
    public Collection<Teesr04Agreemitem> agreementItemsHistory(Teess01Supplier supplier)
            throws FullEconomicsException {
        AgreementItemLogic logic = new AgreementItemLogic();
        Collection<Teesr04Agreemitem> ret = logic.agreementItemsHistory(supplier);
        return ret;
    }

    /**
     * 
     * @param agreemItem
     * @return
     * @throws FullEconomicsException
     */
    public Teesr04Agreemitem findPrevAgreemItem(Teesr04Agreemitem agreemItem)
            throws FullEconomicsException {
        AgreementItemLogic logic = new AgreementItemLogic();
        Teesr04Agreemitem ret = logic.findPrevAgreementItem(agreemItem);
        return ret;
    }

    /**
     * crea un agreement item, debe contener el agreement al que pertenece
     * 
     * @param item
     * @param user
     * @throws FullEconomicsException
     */
    public void createAgreementItem(Teesr04Agreemitem item,
                                    FullEconomicsWslxUser user)
            throws FullEconomicsException {

        AgreementItemLogic logic = new AgreementItemLogic();
        logic.createAgreementItem(item, user);

    }

    /**
     * guarda los cambios hechos en un agreement item
     * 
     * @param item
     * @param user
     * @throws FullEconomicsException
     */
    public void updateAgreementItem(Teesr04Agreemitem item,
                                    FullEconomicsWslxUser user)
            throws FullEconomicsException {

        AgreementItemLogic logic = new AgreementItemLogic();
        logic.updateAgreementItem(item, user);

    }

    /**
     * busca los items pertencientes al agreement
     * 
     * @param agreement
     * @return
     * @throws FullEconomicsException
     */
    public Collection<Teesr04Agreemitem> findAgreementItems(
                                                            Teesr03Agreement agreement)
            throws FullEconomicsException {

        AgreementItemLogic logic = new AgreementItemLogic();
        Collection<Teesr04Agreemitem> ret = logic.findAgreementItems(agreement);
        return ret;

    }

    /**
     * busca los items pertencientes al agreement ordenados por vehiculo
     * 
     * @param agreement
     * @return
     * @throws FullEconomicsException
     */
    public Collection<Teesr04Agreemitem> findAgreementItemsOrderByVehicle(
                                                                          Teesr03Agreement agreement)
            throws FullEconomicsException {

        AgreementItemLogic logic = new AgreementItemLogic();
        Collection<Teesr04Agreemitem> ret = logic
                .findAgreementItemsOrderByVehicle(agreement);
        return ret;

    }

    /**
     * borra el item pasado por parametro
     * 
     * @param item
     * @throws FullEconomicsException
     */
    public void deleteAgreementItem(Teesr04Agreemitem item)
            throws FullEconomicsException {
        AgreementItemLogic logic = new AgreementItemLogic();
        logic.deleteAgreementItem(item);
    }
}
